<!DOCTYPE html>
<html>
{include file="Login/header" /}
<style>
    img{width: 200px}
    span{color: #cc181b}
</style>
<body class="login" mycollectionplug="bind" style="background: #44AAFF">
<div class="login_out"><a href="{:url('index/outLogin')}">切换其他账号登录>></a> </div>
<div class="reg_boder_height_520 reg_boder ">
    <div class="reg_m" >
        <div class="reg_title">
            <div style="font-size: 26px;    ">银行卡绑卡</div>
        </div>
        <form action="{:url('Login/personal_card')}" id="regFrom" method="post">
            <h2><span>*</span>开户银行：</h2>
            <label>
                <select name="bank_code" required  class="txt_input txt_input2" >
                    <?php  foreach(think\Config::get('bank_list') as $key=>$value){  ?>
                    <option value="{$key}">{$value}</option>
                    <?php  } ?>
                </select>
            </label>
            <br/> <br/>

            <h2><span>*</span>开户省市：</h2>
            <label>
                <select name="province" id="province" class="txt_input txt_input2"  ></select>
            </label>
            <label>
                <select  name="city" id="city"  class="txt_input txt_input2" ></select>
            </label>
            <br/> <br/>
            <h2><span>*</span>银行卡号：</h2>
            <label>
                <input type="text" name="bank_card" class="txt_input txt_input2" required  value="" placeholder="">
            </label>
            <h2><span>*</span>银行预留手机号：</h2>
            <label>
                <input type="text" name="phone" class="txt_input txt_input2" required  value="" placeholder="">

            </label>

            <h2><span>*</span>短信验证码：</h2>
            <label>
                <input type="text" name="valid_code" class="txt_input txt_input2 txt_input3" required  value="" placeholder="">
            </label>
            <button type="button" id="vcode" class="btn btn-success">获取短信验证码</button>
            <label>
                <div class="col-sm-12 text-center" style="width: 300px;margin: 0 auto;">
                    <button type="button" id="submit" class="btn btn-success">提交</button>
                </div>
            </label>
        </form>

        <form action="{:url('Login/personal_card')}" style="display: none" id="advanceFrom" method="post">

        </form>
    </div>
</div>


</body>
{include file="Login/footer" /}

<script type="text/javascript">
    dsy._init_area(['province','city']);

    $(document).ready(function(){
        $("#vcode").click(function(){

            var phone = $("input[name='phone']");
            var flag = false;
            var message = "";
            var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/;
            if(phone.val().length !=11){
                message = "长度请输入有效的手机号码！";
            }else if(!myreg.test(phone.val())){
                message = "请输入有效的手机号码！";
            }else{
                flag = true;
            }

            if(!flag){
                phone.val('');
                alert(message);
                phone.focus();
                return false;
            }


            var data = $("#regFrom").serialize();
            toAjax("{:url('User/add_card')}",
                data,"POST",
                function(rs){
                    console.log(rs);

                    if(rs.code == 1){
                        console.log(rs.message);
                        alert(rs.message);
                    }

                    if(rs.code == 0){
                        settime();
                    }
                },
                false,false,this);

        });

        $("#submit").click(function(){
            var valid_code = $("input[name='valid_code']");
            if(valid_code.val().trim()== ''){
                message = "请输入短信验证码！";
            }

            var data = {'valid_code':valid_code.val()}
            toAjax("{:url('User/add_card_advance')}",
                data,"POST",
                function(rs){
                    console.log(rs);

                    if(rs.code == 1){
                        console.log(rs.message);
                        alert(rs.message);
                    }

                    if(rs.code == 0){
                        window.location = rs.data.url;
                    }
                },
                false,false,this);

        });

    });

    var countdown=60;
    function settime() {
        var obj = $('#vcode');
        if (countdown == 0) {
            obj.removeAttr("disabled");
            obj.text("获取短信验证码");
            countdown = 60;
            return;
        } else {
            obj.attr("disabled", true);
            obj.text("重新发送(" + countdown + ")");
            countdown--;
        }
        setTimeout(function() {
                settime() }
            ,1000)
    }
</script>
